<template>
	<view class="body">
		<form @submit="formSubmit">
			<view class="face-wrapper">
				<image src="../../static/default-face.png" class="face" mode=""></image>
			</view>
			<view class="info-wrapper">
				<label class="words-lbl">账号</label>
				<input type="text" name="username" value="" class="input" placeholder="请输入用户名" placeholder-class="graywords">
			</view>
			
			<view class="info-wrapper" style="margin-top: 40upx;">
				<label class="words-lbl">密码</label>
				<input type="text" name="password" value="" class="input" password="true" placeholder="请输入密码" placeholder-class="graywords">
			</view>
			
			<button type="primary" form-type="submit" style="margin-top: 60upx;width: 90%;">注册/登录</button>
		</form>
		
		<!-- //第三方登陆h5不支持，所以隐藏掉 -->
		<!-- #ifndef H5 -->
			<view class="third-wrapper">
				<view class="third-line">
					<view class="single-line">
						<view class="line"></view>
					</view>
					
					<view class="third-words">
						第三方账号登陆
					</view>
					<view class="sing-line">
						<view class="line"></view>
					</view>
				</view>
				
				<view class="third-icos-wrapper">
					<!-- 5+app 用qq登陆 小程序用微信小程序登陆 h5 不支持 -->
					
					<!-- #ifdef APP-PLUS -->
						<image src="../../static/me.png" mode="" class="third-ico"></image>
						<image src="../../static/success.png" mode="" class="third-ico"></image>
					<!-- #endif -->
					
					<!-- #ifdef MP-WEIXIN -->
						<button open-type="getUserInfo" @getuserinfo="wxLogin" class="third-btn-icon">11</button>
					<!-- #endif -->
				</view>
			</view>
		<!-- #endif -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		methods: {
			
			wxLogin(e){
				console.log(e);
			},
			
			formSubmit(e){
				var me=this;
				//拿到输入的账号密码
				var username=e.detail.value.username;
				var password=e.detail.value.password;

				// console.log(username)
				// console.log(password);
				
				//发起注册或者登陆的请求
					uni.request({
					url: 'https://www.imovietrailer.com/superhero/user/registOrLogin?qq=lee57837906',
					data: {
						"username": username,
						"password": password
					},
					method: 'POST',
					success: (res) => {
						// debugger
						if(res.data.status==200){
							var userInfo=res.data.data;
							// console.log(userInfo);
							//保存用户信息到全局缓存中
							uni.setStorageSync("globalUser",userInfo);
							//切换页面跳转，使用tab切换的api
							uni.switchTab({
								url:"../me/me"
							})
						}else if(res.data.status==500){
							uni.showToast({
								title:res.data.msg,
								duration:2000,
								image:"../../static/error.png"
							})
						}
						
					}
				});
			}
		}
	}
</script>

<style>
	@import url("register.css");
</style>
